<?php

namespace Cck\ArticlesSystem\Http\ModelObserves;

use Cck\ArticlesSystem\Http\Models\Category;

class CategoryObserve
{
    public function creating(Category $category)
    {
        if ($category->url_type === Category::URL_TYPE_ID) {
            $category->slug = Category::query()->max('id') + 1;
        }

        if (!$category->slug && $category->url_type === Category::URL_TYPE_ALIAS) {
            $category->slug = randomLetters(5, 10);
        }
    }
}
